<%@ page import="cn.tedu.oa.common.util.ShiroUtils" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>安全设置</title>
    <link rel="icon" href="${pageContext.request.contextPath}/lib/static/login/images/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <style>

    </style>
</head>
<body>
<div class="layui-fluid">
    <hr class="layui-bg-red">
    <div class="layui-row">
        <div class="layui-col-sm6  layui-col-sm-offset3">
            <form class="layui-form layui-form-pane" lay-filter="userEdit">
                <input type="hidden" name="id" value="<%=ShiroUtils.getPrincipal().getId()%>">
                <div class="layui-form-item">
                    <label class="layui-form-label">旧密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" required lay-verify="required|password" lay-verType="tips" placeholder="请输入旧密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="newPassword" required lay-verify="required|newPassword" lay-verType="tips" placeholder="请输入新密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="confirmPassword" required lay-verify="required|confirmPassword" lay-verType="tips" placeholder="请确认新密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="update">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    var baseUrl = '${pageContext.request.contextPath}/sys/user/';

    /*发送ajax请求访问后台*/
    function sendAjaxPostReq($, param, method) {
        $.post(
            baseUrl + method,
            param,
            function (result) {
                if (result.code == 0) {
                    layer.msg(result.msg, {icon: 1, time: 500}, function () {
                        parent.window.location.reload();
                    });
                } else {
                    layer.msg(result.msg, {icon: 5, anim: 6});
                }
            },
            "json"
        );
    }

    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.$;
        //自定义验证规则
        form.verify({
            password: [/(.+){6,12}$/, '密码必须6到12位'],
            newPassword: [/(.+){6,12}$/, '密码必须6到12位'],
            confirmPassword: [/(.+){6,12}$/, '密码必须6到12位'],
        });


        /*表单提交 修改*/
        form.on('submit(update)', function (data) {
            sendAjaxPostReq($, data.field, "updatePasswordById");
            return false;
        });
    });
</script>
</body>
</html>
